package com.sca;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
public class ProviderRunApp {

    private static final Logger log=
            LoggerFactory.getLogger(ProviderRunApp.class);

    public static void main(String[] args) {

        SpringApplication.run(ProviderRunApp.class, args);
    }

    //当配置中心的内容发生变化时。自动刷新
    @RefreshScope
    @RestController
    public class ProviderController{

        @Value("${server.port}")
        private String server;

        @Value("${logging.level.com.sca}")//":"后面为默认值
        private String logLevel;

        @Value("${server.tomcat.threads.max:100}")
        private int maxThread;

        @Value("${page.pageSize:3}")
        private  int pageSize;



        @GetMapping("/provider/max")
        public String doGetMaxThread(){

            return "tomcat的最大数是"+ maxThread;
        }


        @GetMapping("/provider/page")
        public String doGetpageSize(){

            return "页数是"+pageSize;
        }

        @GetMapping("/provider/log")
        public String doGetLogLevel(){
            //System.out.println("log.level="+logLevel);
            log.trace("==log.trace==");
            log.debug("==log.debug==");
            log.warn("==log.warn==");
            log.info("==log.info==");
            log.error("==log.error==");
            return "log level is "+logLevel;
        }


        @GetMapping("/provider/echo/{msg}")
        public String doEcho(@PathVariable String msg) throws InterruptedException {//Echo为回显的含义
            if (msg == null||msg.length()<3) {
              Thread.sleep(5000);
               // throw  new IllegalArgumentException("参数不合法");
                return server+" say: hello "+"参数不正确";
            }
            return server+" say: hello "+msg;

        }
    }
}
